package meterMonitor.controller;

import meterMonitor.biz.SettingBiz;
import meterMonitor.consts.ResponseCode;
import meterMonitor.mapper.SettingMapper;
import meterMonitor.model.Setting;
import meterMonitor.vo.BaseResponseData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("setting")
@RestController
public class SettingController {

    @Autowired
    SettingBiz settingBiz;
    public static final Logger logger = LoggerFactory.getLogger(WaterChartController.class);

    @RequestMapping("updateSetting.do")
    public BaseResponseData updateSetting(int timer){
        BaseResponseData baseResponseData = new BaseResponseData();
        try {
            settingBiz.updateSetting(timer);
            baseResponseData.setCode(ResponseCode.SUCCESS);
            baseResponseData.setMessage("更新成功！");
        } catch (Exception e) {
            logger.error("更新区域信息异常！", e);
            baseResponseData.setCode(ResponseCode.DATA_EXCEPTION);
            baseResponseData.setMessage("更新区域信息失败！");
        }
        return baseResponseData;
    }


    @RequestMapping("getSetting.do")
    public int getSetting(){
        Setting setting = new Setting();
        try {
             setting = settingBiz.getSetting();
        } catch (Exception e) {
            logger.error("查询信息异常！", e);
        }
        return setting.getTimer();

    }

}
